package com.carrot.newsgallery.config;

import com.google.common.net.HttpHeaders;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 该配置无效,因为服务器处理请求的时候会先过过滤器,然后过拦截器,再到mapping来
 * 如果自定义了拦截器,那时候不先处理headers,就会在拦截器报错了,所以要用过滤器来实现
 */

@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
//                .allowedOrigins("http://43.143.1973.195:8080","http://localhost:8080")
                .allowedOrigins("*")
                .allowedHeaders("*")
                .allowedMethods("*")
//                .allowCredentials(true)
                .exposedHeaders(HttpHeaders.SET_COOKIE).maxAge(3600L);
    }
}